//
//  TestFriendCycleVC.m
//  NiubilityProject
//
//  Created by Apple on 2018/6/1.
//  Copyright © 2018年 Apple. All rights reserved.
//

#import "TestFriendCycleVC.h"
#import <UITableView+FDTemplateLayoutCell.h>
#import "DataModel.h"
#import "testFriendCell.h"
#import "YYFPSLabel.h"

@interface TestFriendCycleVC ()

@end

@implementation TestFriendCycleVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    YYFPSLabel *fps = [[YYFPSLabel alloc] initWithFrame:CGRectMake(20, self.view.height - 40, 60, 30)];
    [self.view addSubview:fps];
}
- (void)initTableView{
    [super initTableView];
    [self.tableView registerClass:[testFriendCell class] forCellReuseIdentifier:@"testFriendCellID"];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    testFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testFriendCellID" forIndexPath:indexPath];
    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    return [tableView fd_heightForCellWithIdentifier:@"testFriendCellID" cacheByIndexPath:indexPath configuration:^(testFriendCell *cell) {
        [self configureCell:cell atIndexPath:indexPath];
    }];
    
    return 0;
}
- (void)configureCell:(testFriendCell *)cell atIndexPath:(NSIndexPath *)indexPath{
    cell.fd_enforceFrameLayout = YES;
    if (indexPath.row < self.dataSource.count) {
        cell.dataModel = self.dataSource[indexPath.row];
    }
}
- (void)headerRefresh{
    [self.dataSource removeAllObjects];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"text1" ofType:@"json"];
    NSData *data = [[NSData alloc] initWithContentsOfFile:path];
    NSArray *ar = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    NSArray *ar1 = [DataModel mj_objectArrayWithKeyValuesArray:ar];
    for (int i = 0; i < 10; i++) {
        [self.dataSource addObjectsFromArray:ar1.copy];
    }
    [self.tableView reloadData];
    [JSLoadingView hidenLoadingForView:self.view];
}

-(void)dataServiceDidUpdate:(JSBaseDataService *)service data:(id)data error:(NSError *)error{
    
    
}
@end
